home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_oth / libry31a / libry7.doc < prev    next >
Text File  |  1987-01-20  |  8KB  |  132 lines

  1. .pa
  2.                            VECTOR EMULATIONS
  3.  
  4. Vector emulations are software procedures that mimic  the  operation  of
  5. vector processing hardware.  Of course, the software is not based on the
  6. same principle as the hardware;  but the concept is the same:   specific
  7. procedure  designed to most efficiently perform similar repetitive tasks
  8. on contiguously stored real numbers.  No, I won't tell you how I do  it,
  9. so  don't  ask.   My  vector  emulations  are completely compatible with
  10. Hewlett-Packard's Vector Instruction Set  (VIS).   They  have  the  same
  11. calling  syntax  and  function (that's why I developed them in the first
  12. place - downloading programs from an HP-1000F).   HP  has  a  very  nice
  13. manual  with  examples.   If you are interested, perhaps they would sell
  14. you one (I wouldn't even hazard a guess as to the cost).
  15.  
  16.                Vector Instruction Set (VIS) User's Manual
  17.                Part No. 12824-90001
  18.                Hewlett-Packard Company
  19.                Data Systems Division
  20.                11000 Wolfe Road
  21.                Cupertino, CA 95014
  22.  
  23. You  do not need a math coprocessor (Intel 8087/80287) in order to run a
  24. program linked with LIBRY.LIB;  but it makes a TREMENDOUS difference  (a
  25. factor  of  120  or  so  for  floating  point  operations).   The vector
  26. emulations will run even without a math coprocessor;  but in  that  case
  27. the speed is already so slow that nothing will help.  The improvement in
  28. speed with the vector emulations varies depending on the relative  speed
  29. of your processor and coprocessor.  The greatest improvement is realized
  30. on a PC with a 5MHz-8086/5MHz-8087 pair;  and the least  improvement  is
  31. realized on an AT with an 8MHz-80286/5MHz-80287 pair.
  32.  
  33. Note that the increments (INCR1,INCR2,INCR3),index (M),  and  the  count
  34. (N)  are of the type INTEGER*2.  Reals are of the type REAL*4 and double
  35. precision reals are of the type REAL*8.   There  can  be  no  mixing  of
  36. REAL*4  and REAL*8 types in the same emulation.  To get double precision
  37. use "CALL DVABS(...)" rather than "CALL VABS(...)".
  38.  
  39. It is very important to  BE  SURE  THAT  NO  VECTOR  CROSSES  A  SEGMENT
  40. BOUNDARY (refer to Microsoft FORTRAN manual section 8).  What this means
  41. to the machine is that a vector must  reside  within  a  single  segment
  42. (65536  bytes) or it can not address all of the elements as a group.  In
  43. order to assure this to be the case, NEVER use the  $LARGE  metacommand.
  44. If  you  have no COMMON then you never have to worry about this.  If you
  45. do have COMMON make sure that each COMMON contain  no  more  than  65536
  46. bytes.  Of course, you can have several named COMMONs so this is not too
  47. restrictive a limit on your programs.  Also, if there is more  than  one
  48. vector  passed to the emulator they need not reside in the same segment.
  49. For instance, you can add one real vector with 16384 elements to another
  50. with  16384  elements  and store the result in a third - as long as they
  51. are all in different COMMONs.  Of course, you can add two vectors in the
  52. same  COMMON  provided  their  total  number of elements does not exceed
  53. 16384.  There is a way of getting around this;  but it is  too  involved
  54. to explain here.
  55.  
  56. A  word  of warning...  vector emulations do not like being interrupted.
  57. This is the whole point of "speed at any  cost"  procedures.   For  this
  58. reason, the emulations may interfere with the operation of some "pop-up"
  59. programs and such  things  as  windowing  and  multi-tasking.   This  is
  60. regretably unpredictable.  I can say that the emulations don't interfere
  61. with any of the "pop-up" programs that I have  developed  (like  my  DOS
  62. command  stack  full-screen editor and improved scroller) that "lurk" in
  63. the background;  but I don't know about such programs that  others  have
  64. developed.
  65. .pa
  66. SAMPLE FORTRAN EQUIVALENT OF A VECTOR ADD
  67.  
  68.  
  69.       SUBROUTINE VADD(V1,INCR1,V2,INCR2,V3,INCR3,N)
  70. C
  71. C  VECTOR V3=V1+V2
  72. C
  73.       IMPLICIT INTEGER*2 (I-N)
  74.       IMPLICIT REAL*4 (A-H,O-Z)
  75.       DIMENSION V1(N),V2(N),V3(N)
  76. C
  77.       IF(N.LT.1) GO TO 999
  78.       I1=1
  79.       I2=1
  80.       I3=1
  81. C
  82.       DO 100 I=1,N
  83.       V3(I3)=V1(I1)+V2(I2)
  84.       I1=I1+INCR1
  85.       I2=I2+INCR2
  86.   100 I3=I3+INCR3
  87. C
  88.   999 RETURN
  89.       END
  90. .pa
  91. .ft c
  92. .in 15
  93.                                     SUMMARY OF VECTOR INSTRUCTION SET
  94. ----------------------------------------------------------------------------------------------------------------------
  95.                                                                         SPEED IMPROVEMENT:  PC WITH 8087     HP-1000F
  96. CALLING SYNTAX                                OPERATION                 VECTOR LENGTH:       N=10  N=100   N=10  N=100
  97. ----------------------------------------------------------------------------------------------------------------------
  98. CALL VABS(V1,INCR1,V2,INCR2,N)                (V2(I)=ABS(V1(I)),I=1,N)                        4.0    7.5    4.5    5.1
  99. CALL VADD(V1,INCR1,V2,INCR2,V3,INCR3,N)       (V3(I)=V1(I)+V2(I),I=1,N)                       3.3    3.8    4.9    4.8
  100. CALL VDIV(V1,INCR1,V2,INCR2,V3,INCR3,N)       (V3(I)=V1(I)/V2(I),I=1,N)                       2.5    3.2    5.0    5.7
  101. CALL VDOT(S,V1,INCR1,V2,INCR2,N)              S=SUM(V1(I)*V2(I),I=1,N)                        4.0    4.8    3.5    3.6
  102. CALL VMAB(M,V1,INCR1,N)                       V1(M)=AMAX1(ABS(V1(I)),I=1,N)                   3.5    4.4    3.6    3.6
  103. CALL VMAX(M,V1,INCR1,N)                       V1(M)=AMAX1(V1(I),I=1,N)                        3.5    3.3    4.2    4.4
  104. CALL VMIB(M,V1,INCR1,N)                       V1(M)=AMIN1(ABS(V1(I)),I=1,N)                   3.8    4.8    3.7    3.2
  105. CALL VMIN(M,V1,INCR1,N)                       V1(M)=AMIN1(V1(I),I=1,N)                        3.5    3.5    4.2    3.9
  106. CALL VMOV(V1,INCR1,V2,INCR2,N)                (V2(I)=V1(I),I=1,N)                             3.3    9.0    5.2    6.5
  107. CALL VMPY(V1,INCR1,V2,INCR2,V3,INCR3,N)       (V3(I)=V1(I)*V2(I),I=1,N)                       3.5    3.8    4.8    4.7
  108. CALL VNRM(S,V1,INCR1,N)                       S=SUM(ABS(V1(I)),I=1,N)                         5.3    4.7    3.8    4.5
  109. CALL VPIV(S,V1,INCR1,V2,INCR2,V3,INCR3,N)     (V3(I)=S*V1(I)+V2(I),I=1,N)                     3.4    3.5    4.6    5.2
  110. CALL VSAD(S,V1,INCR1,V2,INCR2,N)              (V2(I)=S+V1(I),I=1,N)                           3.4    4.0    3.7    4.2
  111. CALL VSDV(S,V1,INCR1,V2,INCR2,N)              (V2(I)=S/V1(I),I=1,N)                           3.0    3.2    4.5    4.4
  112. CALL VSMY(S,V1,INCR1,V2,INCR2,N)              (V2(I)=S*V1(I),I=1,N)                           3.4    4.0    4.0    4.5
  113. CALL VSSB(S,V1,INCR1,V2,INCR2,N)              (V2(I)=S-V1(I),I=1,N)                           3.4    5.3    3.6    4.1
  114. CALL VSUB(V1,INCR1,V2,INCR2,V3,INCR3,N)       (V3(I)=V1(I)-V2(I),I=1,N)                       3.3    3.8    5.5    5.6
  115. CALL VSUM(S,V1,INCR1,N)                       (V3(I)=V1(I)+V2(I),I=1,N)                       3.5    4.3    3.5    4.1
  116. CALL VSWP(V1,INCR1,V2,INCR2,N)                (V1(I)<->V2(I),I=1,N)                           3.2    5.0    5.0    5.7
  117. CALL VMIX(INDEX,V1,V2,N)                      (V2(I)=V1(INDEX(I)),I=1,N)                      1.8    2.7     NA     NA
  118. CALL VMXI(INDEX,V1,V2,N)                      (V2(INDEX(I))=V1(I),I=1,N)                      1.8    1.7     NA     NA
  119. CALL CLAMP(VMIN,VMAX,V,N)                     (V1(I)=AMAX1(VMIN,AMIN1(VMAX,V(I))),I=1,N)      8.0    9.0     NA     NA
  120. H=HORNER(C,X,N)                               H=SUM(C(I)*X**(I-1),I=1,N)                      3.5    4.3     NA     NA
  121. ----------------------------------------------------------------------------------------------------------------------
  122. The above table shows, for instance, that an emulated add of two vector having length 100 is 7.5 times as fast
  123. as the same operation in FORTRAN on a "stock" PC with an 8087 math coprocessor.
  124.  
  125. note 1: there is little or no improvement for n<10 and runtimes may increase for n<5.
  126. note 2: for double precision add a "D" prefix (e.g. DVABS, DVADD, ..., DCLAMP, DHORNE).
  127. note 3: vectors must not cross a segment boundary (see section 8 of Microsoft FORTRAN user's guide).
  128. note 4: all integers (e.g. INCR1,INCR2,INCR3,n...) are of the INTEGER*2 type.
  129. note 5: increments (viz. INCR1,INCR2,INCR3) can be positive, negative, or zero.
  130. .ft e
  131. .in 10
  132.